package leetcode;

public class Q0066 {
    public int[] plusOne(int[] digits) {
        int c = 0;
        for (int i = digits.length - 1; i >= 0; i--) {
            digits[i] += 1;
            c = digits[i] / 10;
            if (c == 0) break;
            else digits[i] %= 10;
        }
        if (c == 0) return digits;
        int[] res = new int[digits.length + 1];
        res[0] = 1;
        System.arraycopy(digits, 0, res, 1, res.length - 1);
        return res;
    }
}
